package com.small.flowable.modules.app.controllers;


import com.common.basis.result.Result;
import com.common.basis.result.ResultSet;
 import com.small.flowable.modules.app.dto.rsp.ProcessInstanceRsp;
import com.small.flowable.modules.app.services.ProcessInstanceService;
import lombok.AllArgsConstructor;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 流程实例管理
 *
 * @author wangguochao*/
@RestController
@AllArgsConstructor
@RequestMapping("processInstance")
public class ProcessInstanceController {

    private final ProcessInstanceService processInstanceService;



    /**
     * 获取当前正在执行的流程实例列表
     **/
    @GetMapping("runtime/list")
    public Result<List<ProcessInstanceRsp>> getRuntimeProcessInstanceList() {
        return  ResultSet.go(processInstanceService.getRuntimeProcessInstanceList());
    }

    /**
     * 开启流程实例
     * @return 流程实例
     */
    @PostMapping("startProcessInstance")
    public Result<String> startProcessInstance(@RequestParam String processDefinitionKey) {
        ProcessInstance processInstance = processInstanceService.startProcessInstance(processDefinitionKey);
        return  ResultSet.go(processInstance.getProcessInstanceId());
    }
    
}
